#include <iostream>
#include <vector>
using namespace std;

class Friend_Circle{
private:
    vector<vector<int>> Matrix;
    vector<bool> visited;
    int node_num;
public:
    Friend_Circle(vector<vector<int>>& M,vector<bool> &v,int i);
    void DFS(int i);
    int Find_CircleNum();
};
Friend_Circle::Friend_Circle(vector<vector<int>> &M,vector<bool> &v,int i) {
    Matrix = M;
    visited = v;
    node_num = i;
}
void Friend_Circle::DFS(int i) {
    int N = Matrix.size();
    for(int j = 0;j < N;j++)
    {
        if(Matrix[i][j] == 1 && visited[j] == true)
        {
            visited[j] = false;
            DFS(j);
        }
    }
}
int Friend_Circle::Find_CircleNum() {
    int N = Matrix.size();
    int circle = 0; //朋友圈数
    for(int i = 0;i < N;i++)
    {
        if(visited[i] == true) //还没被遍历过
        {
            //dfs(M,visit,i); //使用dfs搜索并标记与其相关的学生
            DFS(i);   //使用dfs搜索并标记与其相关的学生
            circle++;
        }
    }
    return circle;
}
int main()
{
    vector<bool > v(6,true);
    vector<vector<int>> matrix ={{1,0,1,0,0,1},
                                 {0,1,0,0,0,0},
                                 {1,0,1,0,1,0},
                                 {0,0,0,1,0,0},
                                 {0,0,1,0,1,0},
                                 {1,0,0,1,0,1}};
    int node_num,vec_num;
    cin>>node_num>>vec_num;

    Friend_Circle f = Friend_Circle(matrix,v,0);
    int circlenum = f.Find_CircleNum();
    cout<<circlenum<<endl;

}



